package com.atguigu.test05;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;


/**
 * @author haoranlu
 * @project IntelliJ IDEA
 */
public class JDBCToolsV1{
    private static DataSource ds;
    static {
        //静态代码块
        try {
            Properties pro = new Properties();
            pro.load(JDBCToolsV1.class.getClassLoader().getResourceAsStream("druid.properties"));
            ds = DruidDataSourceFactory.createDataSource(pro);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
    public static Connection getConnection() throws SQLException {

        //方式一:DriverManager.getConnection()
        //方式二:连接池对象.getConnection()
        return ds.getConnection();
    }
}
